package com.syc.ext;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;

import java.util.Map;

public class CustomAutoGenerator extends AutoGenerator {

	private Map<String, Object> customParams;

	public CustomAutoGenerator(Map<String, Object> customParams) {
		this.customParams = customParams;
	}

	@Override
	public void execute() {
		if (null == this.config) {
			this.config = new ConfigBuilder(super.getPackageInfo(), super.getDataSource(), super.getStrategy(),
					super.getTemplate(), super.getGlobalConfig());
			if (null != this.injectionConfig) {
				this.injectionConfig.setConfig(this.config);
			}
		}
		if (null == super.getTemplateEngine()) {
			if (customParams != null) {
				setTemplateEngine(new CustomTemplateEngine(customParams));
			}
			else {
				setTemplateEngine(new CustomTemplateEngine());
			}
		}
		getTemplateEngine().init(this.pretreatmentConfigBuilder(this.config)).mkdirs().batchOutput().open();
	}

}
